package com.example.analysis.service.impl;

import com.example.analysis.entity.Course;
import com.example.analysis.entity.Teacher;
import com.example.analysis.entity.Teacher;
import com.example.analysis.mapper.TeacherDao;
import com.example.analysis.service.TeacherService;
import com.example.analysis.utils.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {
    @Resource
    private TeacherDao TeacherDao;
    @Autowired
    private TeacherDao teacherDao;


    @Override
    public Response<Teacher> insert(Teacher aTeacher) {
        try {
            TeacherDao.insert(aTeacher);
            return new Response<>(true, "Insert success", null);
        } catch (Exception e) {
            return new Response<>(false, "Insert failed: " + e.getMessage(), null);
        }
    }

    @Override
    public Response<Teacher> getById(String TeacherId) {
        Teacher aTeacher = TeacherDao.selectByPrimaryKey(TeacherId);
        if (aTeacher != null) {
            return new Response<>(true, "Success", aTeacher);
        } else {
            return new Response<>(false, "Administration not found", null);
        }
    }
    public Response<List<Teacher>> getByName(String TeacherName) {
        List<Teacher> aTeacher = TeacherDao.selectByName(TeacherName);
        if (aTeacher != null) {
            return new Response<>(true, "Success", aTeacher);
        } else {
            return new Response<>(false, "Administration not found", null);
        }
    }

    @Override
    public Response<List<Teacher>> getAll() {
        List<Teacher> teacherList = teacherDao.getAll();

        if (!teacherList.isEmpty()) {
            return new Response<>(true, "Success", teacherList);
        } else {
            return new Response<>(false, "Administration not found", null);
        }
    }
}
